home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Icon 8.1 / msm-2 / iconc.sit / tccomp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-19  |  5.6 KB  |  271 lines  |  [TEXT/MPS ]

  1. /*
  2.  * tccomp.c - routines for compiling and linking the C program produced
  3.  *   by the translator.
  4.  */
  5. #include "::h:gsupport.h"
  6. #include "globals.h"
  7. #include "trans.h"
  8. #include "tree.h"
  9. #include "tcode.h"
  10. #include "tsym.h"
  11. #include "tproto.h"
  12.  
  13. extern char *refpath;
  14.  
  15. /*
  16.  * The following code is operating-system dependent [@tccomp.01].  Definition
  17.  *  of ExeFlag and LinkLibs.
  18.  */
  19.  
  20. #if PORT
  21.    /* something is needed */
  22. Deliberate Syntax Error
  23. #endif                        /* PORT */
  24.  
  25. #if UNIX || AMIGA || ATARI_ST || MACINTOSH || MSDOS || MVS || VM || OS2
  26. #define ExeFlag "-o"
  27. #define LinkLibs " -lm"
  28. #endif                        /* UNIX ... */
  29.  
  30. #if VMS
  31. #include file
  32. #define ExeFlag "link/exe="
  33. #define LinkLibs ""
  34. #endif                        /* VMS */
  35.  
  36. /*
  37.  * End of operating-system specific code.
  38.  */
  39.  
  40. /*
  41.  * Structure to hold the list of Icon run-time libraries that must be
  42.  *  linked in.
  43.  */
  44. struct lib {
  45.    char *libname;
  46.    int nm_sz;
  47.    struct lib *next;
  48.    };
  49. static struct lib *liblst;
  50. static int lib_sz = 0;
  51.  
  52. /*
  53.  * addlib - add a new library to the list the must be linked.
  54.  */
  55. novalue addlib(libname)
  56. char *libname;
  57.    {
  58.    static struct lib **nxtlib = &liblst;
  59.    struct lib *l;
  60.  
  61.    l = NewStruct(lib);
  62.  
  63. /*
  64.  * The following code is operating-system dependent [@tccomp.02].
  65.  *   Change path syntax if necessary.
  66.  */
  67.  
  68. #if PORT
  69.    /* something is needed */
  70. Deliberate Syntax Error
  71. #endif                        /* PORT */
  72.  
  73. #if UNIX || AMIGA || ATARI_ST || MACINTOSH || MSDOS || MVS || OS2 || VM
  74.    l->libname = libname;
  75.    l->nm_sz = strlen(libname);
  76. #endif                        /* UNIX ... */
  77.  
  78. #if VMS
  79.    /* change directory string to VMS format */
  80.    {
  81.       struct fileparts *fp;
  82.       char   *newlibname = alloc(strlen(libname) + 20);
  83.  
  84.       strcpy(newlibname, libname);
  85.       fp = fparse(libname);
  86.       if (strcmp(fp->name, "rt") == 0 && strcmp(fp->ext, ".olb") == 0)
  87.          strcat(newlibname, "/lib/include=data");
  88.       else
  89.      strcat(newlibname, "/lib");
  90.       l->libname = newlibname;
  91.       l->nm_sz = strlen(newlibname);
  92.       }
  93. #endif                        /* VMS */
  94.  
  95. /*
  96.  * End of operating-system specific code.
  97.  */
  98.  
  99.    l->next = NULL;
  100.    *nxtlib = l;
  101.    nxtlib = &l->next;
  102.    lib_sz += l->nm_sz + 1;
  103.    }
  104.  
  105. /*
  106.  * ccomp - perform C compilation and linking.
  107.  */
  108. #if MSDOS
  109. int ccomp(srcname, exename)
  110.    char *srcname, *exename;
  111.    {
  112.    fprintf(stderr, "C compilation via iconc not supported\n");
  113.    fflush(stderr);
  114.    }
  115. #else                    /* MSDOS */
  116. int ccomp(srcname, exename)
  117. char *srcname;
  118. char *exename;
  119.    {
  120.    struct lib *l;
  121.    char sbuf[MaxFileName];        /* file name construction buffer */
  122.    char *buf;
  123.    char *s;
  124.    char *dlrgint;
  125.    int cmd_sz, opt_sz, flg_sz, exe_sz, src_sz;
  126.  
  127.    /*
  128.     * Compute the sizes of the various parts of the command line
  129.     *  to do the compilation.
  130.     */
  131.    cmd_sz = strlen(c_comp);
  132.    opt_sz = strlen(c_opts);
  133.    flg_sz = strlen(ExeFlag);
  134.    exe_sz = strlen(exename);
  135.    src_sz = strlen(srcname);
  136.    lib_sz += strlen(LinkLibs);
  137.    if (!largeints) {
  138.       dlrgint = makename(sbuf, refpath, "dlrgint", ObjSuffix);
  139.       lib_sz += strlen(dlrgint) + 1;
  140.       }
  141.  
  142. /*
  143.  * The following code is operating-system dependent [@tccomp.03].
  144.  *  Construct the command line to do the compilation.
  145.  */
  146.  
  147. #if PORT
  148.    /* something is needed */
  149. Deliberate Syntax Error
  150. #endif                        /* PORT */
  151.  
  152. #if AMIGA || ATARI_ST || MACINTOSH || MSDOS || MVS || VM || OS2
  153.    /* something may be needed */
  154. Deliberate Syntax Error
  155. #endif                        /* AMIGA || ... */
  156.  
  157. #if UNIX
  158.  
  159. #ifdef XIcon
  160.    lib_sz += strlen(" -L") +
  161.              strlen(refpath) +
  162.          strlen(" -lXpm ");
  163.    lib_sz += strlen(ICONC_XLIB);
  164. #endif                        /* XIcon */
  165.  
  166.    buf = alloc((unsigned int)cmd_sz + opt_sz + flg_sz + exe_sz + src_sz +
  167.                  lib_sz + 5);
  168.    strcpy(buf, c_comp);
  169.    s = buf + cmd_sz;
  170.    *s++ = ' ';
  171.    strcpy(s, c_opts);
  172.    s += opt_sz;
  173.    *s++ = ' ';
  174.    strcpy(s, ExeFlag);
  175.    s += flg_sz;
  176.    *s++ = ' ';
  177.    strcpy(s, exename);
  178.    s += exe_sz;
  179.    *s++ = ' ';
  180.    strcpy(s, srcname);
  181.    s += src_sz;
  182.    if (!largeints) {
  183.       *s++ = ' ';
  184.       strcpy(s, dlrgint);
  185.       s += strlen(dlrgint);
  186.       }
  187.    for (l = liblst; l != NULL; l = l->next) {
  188.       *s++ = ' ';
  189.       strcpy(s, l->libname);
  190.       s += l->nm_sz;
  191.       }
  192.  
  193. #ifdef XIcon
  194.    strcpy(s," -L");
  195.    strcat(s, refpath);
  196.    strcat(s," -lXpm ");
  197.    strcat(s, ICONC_XLIB);
  198.    s += strlen(s);
  199. #endif                        /* XIcon */
  200.  
  201.    strcpy(s, LinkLibs);
  202.  
  203.    if (system(buf) != 0)
  204.       return ErrorExit;
  205.    strcpy(buf, "strip ");
  206.    s = buf + 6;
  207.    strcpy(s, exename);
  208.    system(buf);
  209. #endif                        /* UNIX ... */
  210.  
  211. #if VMS
  212.  
  213. #ifdef XIcon
  214. #ifdef XpmFormat
  215.    lib_sz += strlen(refpath) + strlen("Xpm/lib,");
  216. #endif                        /* XpmFormat */
  217.    lib_sz += 1 + strlen(refpath) + strlen("X11.opt/opt");
  218. #endif                        /* XIcon */
  219.  
  220.    buf = alloc((unsigned int)cmd_sz + opt_sz + flg_sz + exe_sz + src_sz +
  221.                  lib_sz + 5);
  222.    strcpy(buf, c_comp);
  223.    s = buf + cmd_sz;
  224.    strcpy(s, c_opts);
  225.    s += opt_sz;
  226.    *s++ = ' ';
  227.    strcpy(s, srcname);
  228.  
  229.    if (system(buf) == 0)
  230.       return ErrorExit;
  231.    strcpy(buf, ExeFlag);
  232.    s = buf + flg_sz;
  233.    strcpy(s, exename);
  234.    s += exe_sz;
  235.    *s++ = ' ';
  236.    strcpy(s, srcname);
  237.    s += src_sz - 1;
  238.    strcpy(s, "obj");
  239.    s += 3;
  240.    if (!largeints) {
  241.       *s++ = ',';
  242.       strcpy(s, dlrgint);
  243.       s += strlen(dlrgint);
  244.       }
  245.    for (l = liblst; l != NULL; l = l->next) {
  246.       *s++ = ',';
  247.       strcpy(s, l->libname);
  248.       s += l->nm_sz;
  249.       }
  250. #ifdef XIcon
  251.    strcat(s, ",");
  252. #ifdef XpmFormat
  253.    strcat(s, refpath);
  254.    strcat(s, "Xpm/lib,");
  255. #endif                        /* XpmFormat */
  256.    strcat(s, refpath);
  257.    strcat(s, "X11.opt/opt");
  258. #endif                        /* XIcon */
  259.  
  260.    if (system(buf) == 0)
  261.       return ErrorExit;
  262. #endif                        /* VMS */
  263.  
  264. /*
  265.  * End of operating-system specific code.
  266.  */
  267.  
  268.    return NormalExit;
  269.    }
  270. #endif                    /* MSDOS */
  271.